package leetcode;

import java.util.ArrayList;
import java.util.List;

public class LC40 {
    public static void main(String[] args) {
        ArrayList<Object> list = new ArrayList<>();
        System.out.println(list.get(0));
    }
    public List<List<Integer>> levelOrder(TreeNode root) {
        List<List<Integer>> ans = new ArrayList<>();
        level(root,0,ans);
        return ans;
    }
    public void level(TreeNode root, int i, List<List<Integer>> ans){
        if (root == null) return;
        List<Integer> list;
        if (i > ans.size() - 1){
            list = new ArrayList<>();
            ans.add(list);
        }else
            list = ans.get(i);
        list.add(root.val);
        i = i + 1;
        level(root.left,i,ans);
        level(root.right,i,ans);
    }
}
